package tpenchere.controllers;

import org.jdesktop.application.Action;

import tpenchere.model.Categorie;
import tpenchere.model.Enchere;
import tpenchere.model.Produit;
import tpenchere.service.EnchereServiceOperations;
import tpenchere.ui.AbstractView;
import tpenchere.ui.contents.BidHistoryWindow;

/**
 * 
 */
public class BidHistoryController extends DefaultController {

	/** the view is useful to retrieve info (e.g. the selected item) */
	private final BidHistoryWindow view;
	private int productId;

	public BidHistoryController(BidHistoryWindow pView) {
		view = pView;
		this.productId = productId;
	}
	
	@Action(name = "view.bid.button.cancel")
	public void cancel() {
		this.switchToView(AbstractView.ViewType.HOME);
	}
	
	public void loadLog() {
		EnchereServiceOperations serviceImpl = provider.getService();
		Produit p = new Produit();
		p.idProduit = productId;
		p.pseudoVendeur = "";
		p.libelle = "";
		p.descriptif = "";
		p.echeance = 1;
		p.categorie = new Categorie();
		p.categorie.categorieFille = new Categorie[0];
		p.categorie.nom = "";
		p.prixDepart = 1f;
		p.prixImmediat = 1f;
		Enchere[] e = serviceImpl.getEnchereFor(p);
		StringBuilder log = new StringBuilder();
		
		for(int i = 0; i < e.length; i++) {
			log.append("New bid from " + e[i].getPseudo() + " : " + e[i].getPrix() + "\n");
		}
		view.getLog().setText(log.toString());
	}

	public int getProductId() {
		return productId;
	}

	public void setProductId(int productId) {
		this.productId = productId;
	}
}
